package main;

import java.awt.Font;
import java.util.ArrayList;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.BoxAndWhiskerToolTipGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.BoxAndWhiskerRenderer;
import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset;

public class StatisticalBoxPlot
{
    private DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    private final CategoryAxis xAxis = new CategoryAxis("Intelligence Type");
    private final NumberAxis yAxis = new NumberAxis("Number of Steps");
    private final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    private CategoryPlot plot;
    private int mapType;
    
    public StatisticalBoxPlot(int map)
    {
    	mapType = map;
    	yAxis.setAutoRangeIncludesZero(false);
    	renderer.setFillBox(false);
    	renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    }
    public void addInfo(int rangeType, int intelligenceType, int[] data)//range is category, intelligence is series
    {
    	ArrayList<Integer> dataInArrayListFormat = new ArrayList<Integer>();
    	for (int index = 0; index < data.length; index++)
    		dataInArrayListFormat.add(data[index]);
    	dataset.add(dataInArrayListFormat, getIntelligenceName(intelligenceType), getRangeName(rangeType));
    }
    public String getIntelligenceName(int intelligenceType)
    {
    	switch(intelligenceType)
    	{
    	case 0: return "2 Agent Swarm";
    	case 1: return "4 Agent Swarm";
    	case 2: return "8 Agent Swarm";
    	case 3: return "2 Vision Range Artificial";
    	case 4: return "3 Vision Range Artificial";
    	case 5: return "4 Vision Range Artificial";
    	default: return null;
    	}
    }
    public String getRangeName(int rangeType)
    {
    	return "Range "+rangeType+" ["+((rangeType*5)-4)+","+(rangeType*5)+"]";
    }
    public String getMapName()
    {
    	switch(mapType)
    	{
    	case 0: return "Thirty Percent Obstacle Map";
    	case 1: return "Forty Percent Obstacle Map";
    	case 2: return "Fifty Percent Obstacle Map";
    	default: return null;
    	}
    }
    public ChartPanel getChartPanel()
    {
    	plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    	final JFreeChart chart = new JFreeChart(getMapName(), new Font("SansSerif", Font.BOLD, 14),plot,true);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(450, 670));
        return chartPanel;
    }
}